import {
    wxRequest
} from '../../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()

Page({
    data: {
        imgUrl: app.globalData.uploadsUrl,
        infoList: [],

        auditTypeList: [
            { key: 1, value: '审核通过' },
            { key: 2, value: '审核驳回' },
        ],
        auditTypeIndex: 0,
        auditType: 1,
        imgSrc: ''
    },

    onLoad: function (options) {
        this.data.infoList = wx.getStorageSync('auditItem')
        let imgSrc = this.data.imgUrl + this.data.infoList.invoicePath
        console.log(this.data.infoList);
        this.setData({
            infoList: this.data.infoList,
            auditTypeList: this.data.auditTypeList,
            imgSrc
        })
    },

    // 审核
    formSubmit: function (e) {
        var formdata = e.detail.value;
        console.log(formdata);

        let params = {
            ...formdata,
            id: this.data.infoList.id
        }

        var url = '/odr/protected/account/auditWithdraw';
        var title = "审核完成"

        _wxRequest.wxTonkenAjax({
            url: app.globalData.apiUrl + url,
            method: 'POST',
            data: params
        }, (res) => {
            console.log('审核结果：', res)

            wx.showToast({
                title
            })
            setTimeout(() => {
                wx.redirectTo({
                    url: '/pages/finance_account/withdraw_audit/withdraw_audit',
                })
            }, 1500)
        })
    },

    // 使用条件类型
    pickerChangeCondition: function (e) {
        var index = e.detail.value;
        var auditTypeList = this.data.auditTypeList;
        var auditType = ''
        auditTypeList.map((item, i) => {
            if (i == index) {
                auditType = item.key
            }
        })

        this.setData({
            auditTypeIndex: index,
            auditType
        })
    },

    imgView: function (e) {
        var src = e.target.dataset.url; //获取data-src
        var imgList = [e.target.dataset.url]; //获取data-list
        //图片预览
        wx.previewImage({
            current: src, // 当前显示图片的http链接
            urls: imgList // 需要预览的图片http链接列表
        })
    },

    onUnload: function () {
        wx.removeStorageSync('auditItem')
    },

    onHide: function () {},

    onShow: function () {

    },

})